// $ANTLR 3.4 C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g 2012-11-07 15:57:03

  package practica8;
  import java.util.Hashtable;


import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;

@SuppressWarnings({"all", "warnings", "unchecked"})
public class ExpresionesParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "ASIGNA", "BLANCO", "DIGITO", "DIV", "IDENT", "LETRA", "MAS", "MENOS", "MULT", "NUMERO", "PARENTESIS_A", "PARENTESIS_C", "PUNTO_COMA"
    };

    public static final int EOF=-1;
    public static final int ASIGNA=4;
    public static final int BLANCO=5;
    public static final int DIGITO=6;
    public static final int DIV=7;
    public static final int IDENT=8;
    public static final int LETRA=9;
    public static final int MAS=10;
    public static final int MENOS=11;
    public static final int MULT=12;
    public static final int NUMERO=13;
    public static final int PARENTESIS_A=14;
    public static final int PARENTESIS_C=15;
    public static final int PUNTO_COMA=16;

    // delegates
    public Parser[] getDelegates() {
        return new Parser[] {};
    }

    // delegators


    public ExpresionesParser(TokenStream input) {
        this(input, new RecognizerSharedState());
    }
    public ExpresionesParser(TokenStream input, RecognizerSharedState state) {
        super(input, state);
    }

    public String[] getTokenNames() { return ExpresionesParser.tokenNames; }
    public String getGrammarFileName() { return "C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g"; }



    		Hashtable variables = new Hashtable();
    		
    		private ArrayList<RecognitionException> errors = new ArrayList<RecognitionException>();
    		public ArrayList<RecognitionException> getErrors() {
    		   return errors;
    		}
    		@Override
    		public void reportError (RecognitionException e) {
    		   String msg = getErrorMessage(e, getTokenNames());
    		   System.err.println(msg);
    		   errors.add(e);
    		}



    // $ANTLR start "entrada"
    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:31:1: entrada : ( instruccion | asignacion )* ;
    public final void entrada() throws RecognitionException {
        try {
            // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:31:9: ( ( instruccion | asignacion )* )
            // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:31:11: ( instruccion | asignacion )*
            {
            // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:31:11: ( instruccion | asignacion )*
            loop1:
            do {
                int alt1=3;
                int LA1_0 = input.LA(1);

                if ( ((LA1_0 >= NUMERO && LA1_0 <= PARENTESIS_A)) ) {
                    alt1=1;
                }
                else if ( (LA1_0==IDENT) ) {
                    int LA1_3 = input.LA(2);

                    if ( (LA1_3==ASIGNA) ) {
                        alt1=2;
                    }
                    else if ( (LA1_3==DIV||(LA1_3 >= MAS && LA1_3 <= MULT)||LA1_3==PUNTO_COMA) ) {
                        alt1=1;
                    }


                }


                switch (alt1) {
            	case 1 :
            	    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:31:12: instruccion
            	    {
            	    pushFollow(FOLLOW_instruccion_in_entrada58);
            	    instruccion();

            	    state._fsp--;
            	    if (state.failed) return ;

            	    }
            	    break;
            	case 2 :
            	    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:31:24: asignacion
            	    {
            	    pushFollow(FOLLOW_asignacion_in_entrada60);
            	    asignacion();

            	    state._fsp--;
            	    if (state.failed) return ;

            	    }
            	    break;

            	default :
            	    break loop1;
                }
            } while (true);


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "entrada"



    // $ANTLR start "instruccion"
    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:34:1: instruccion : e= expr PUNTO_COMA ;
    public final void instruccion() throws RecognitionException {
        int e =0;


        try {
            // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:34:13: (e= expr PUNTO_COMA )
            // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:34:15: e= expr PUNTO_COMA
            {
            pushFollow(FOLLOW_expr_in_instruccion73);
            e=expr();

            state._fsp--;
            if (state.failed) return ;

            match(input,PUNTO_COMA,FOLLOW_PUNTO_COMA_in_instruccion75); if (state.failed) return ;

            if ( state.backtracking==0 ) {System.out.println("Expresion: " + e);}

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "instruccion"



    // $ANTLR start "expr"
    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:36:1: expr returns [int res=0] : e1= exp_mult ( ( MAS e2= exp_mult ) | ( MENOS e2= exp_mult ) )* ;
    public final int expr() throws RecognitionException {
        int res = 0;


        int e1 =0;

        int e2 =0;


        try {
            // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:36:26: (e1= exp_mult ( ( MAS e2= exp_mult ) | ( MENOS e2= exp_mult ) )* )
            // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:36:28: e1= exp_mult ( ( MAS e2= exp_mult ) | ( MENOS e2= exp_mult ) )*
            {
            pushFollow(FOLLOW_exp_mult_in_expr91);
            e1=exp_mult();

            state._fsp--;
            if (state.failed) return res;

            if ( state.backtracking==0 ) {res=e1;}

            // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:36:50: ( ( MAS e2= exp_mult ) | ( MENOS e2= exp_mult ) )*
            loop2:
            do {
                int alt2=3;
                int LA2_0 = input.LA(1);

                if ( (LA2_0==MAS) ) {
                    alt2=1;
                }
                else if ( (LA2_0==MENOS) ) {
                    alt2=2;
                }


                switch (alt2) {
            	case 1 :
            	    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:36:51: ( MAS e2= exp_mult )
            	    {
            	    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:36:51: ( MAS e2= exp_mult )
            	    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:36:52: MAS e2= exp_mult
            	    {
            	    match(input,MAS,FOLLOW_MAS_in_expr97); if (state.failed) return res;

            	    pushFollow(FOLLOW_exp_mult_in_expr101);
            	    e2=exp_mult();

            	    state._fsp--;
            	    if (state.failed) return res;

            	    if ( state.backtracking==0 ) {res=res+e2;}

            	    }


            	    }
            	    break;
            	case 2 :
            	    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:36:83: ( MENOS e2= exp_mult )
            	    {
            	    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:36:83: ( MENOS e2= exp_mult )
            	    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:36:84: MENOS e2= exp_mult
            	    {
            	    match(input,MENOS,FOLLOW_MENOS_in_expr107); if (state.failed) return res;

            	    pushFollow(FOLLOW_exp_mult_in_expr111);
            	    e2=exp_mult();

            	    state._fsp--;
            	    if (state.failed) return res;

            	    if ( state.backtracking==0 ) {res=res-e2;}

            	    }


            	    }
            	    break;

            	default :
            	    break loop2;
                }
            } while (true);


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return res;
    }
    // $ANTLR end "expr"



    // $ANTLR start "exp_mult"
    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:38:1: exp_mult returns [int res=0] : e1= exp_base ( ( MULT e2= exp_base ) | ( DIV e2= exp_base ) )* ;
    public final int exp_mult() throws RecognitionException {
        int res = 0;


        int e1 =0;

        int e2 =0;


        try {
            // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:38:30: (e1= exp_base ( ( MULT e2= exp_base ) | ( DIV e2= exp_base ) )* )
            // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:38:32: e1= exp_base ( ( MULT e2= exp_base ) | ( DIV e2= exp_base ) )*
            {
            pushFollow(FOLLOW_exp_base_in_exp_mult130);
            e1=exp_base();

            state._fsp--;
            if (state.failed) return res;

            if ( state.backtracking==0 ) {res=e1;}

            // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:38:54: ( ( MULT e2= exp_base ) | ( DIV e2= exp_base ) )*
            loop3:
            do {
                int alt3=3;
                int LA3_0 = input.LA(1);

                if ( (LA3_0==MULT) ) {
                    alt3=1;
                }
                else if ( (LA3_0==DIV) ) {
                    alt3=2;
                }


                switch (alt3) {
            	case 1 :
            	    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:38:55: ( MULT e2= exp_base )
            	    {
            	    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:38:55: ( MULT e2= exp_base )
            	    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:38:56: MULT e2= exp_base
            	    {
            	    match(input,MULT,FOLLOW_MULT_in_exp_mult136); if (state.failed) return res;

            	    pushFollow(FOLLOW_exp_base_in_exp_mult140);
            	    e2=exp_base();

            	    state._fsp--;
            	    if (state.failed) return res;

            	    if ( state.backtracking==0 ) {res=res*e2;}

            	    }


            	    }
            	    break;
            	case 2 :
            	    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:38:88: ( DIV e2= exp_base )
            	    {
            	    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:38:88: ( DIV e2= exp_base )
            	    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:38:89: DIV e2= exp_base
            	    {
            	    match(input,DIV,FOLLOW_DIV_in_exp_mult146); if (state.failed) return res;

            	    pushFollow(FOLLOW_exp_base_in_exp_mult150);
            	    e2=exp_base();

            	    state._fsp--;
            	    if (state.failed) return res;

            	    if ( state.backtracking==0 ) {res=res/e2;}

            	    }


            	    }
            	    break;

            	default :
            	    break loop3;
                }
            } while (true);


            }

        }
        catch (ArithmeticException ex) {

               res = 0;
               System.err.println("ERROR: Fallo aritmetico.");

        }

        finally {
        	// do for sure before leaving
        }
        return res;
    }
    // $ANTLR end "exp_mult"



    // $ANTLR start "exp_base"
    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:44:1: exp_base returns [int res=0] : (n= NUMERO |i= IDENT | PARENTESIS_A e= expr PARENTESIS_C );
    public final int exp_base() throws RecognitionException {
        int res = 0;


        Token n=null;
        Token i=null;
        int e =0;


        try {
            // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:44:30: (n= NUMERO |i= IDENT | PARENTESIS_A e= expr PARENTESIS_C )
            int alt4=3;
            switch ( input.LA(1) ) {
            case NUMERO:
                {
                alt4=1;
                }
                break;
            case IDENT:
                {
                alt4=2;
                }
                break;
            case PARENTESIS_A:
                {
                alt4=3;
                }
                break;
            default:
                if (state.backtracking>0) {state.failed=true; return res;}
                NoViableAltException nvae =
                    new NoViableAltException("", 4, 0, input);

                throw nvae;

            }

            switch (alt4) {
                case 1 :
                    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:44:32: n= NUMERO
                    {
                    n=(Token)match(input,NUMERO,FOLLOW_NUMERO_in_exp_base175); if (state.failed) return res;

                    if ( state.backtracking==0 ) {res = new Integer(n.getText()).intValue();}

                    }
                    break;
                case 2 :
                    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:46:32: i= IDENT
                    {
                    i=(Token)match(input,IDENT,FOLLOW_IDENT_in_exp_base244); if (state.failed) return res;

                    if ( state.backtracking==0 ) {if (variables.get(i.getText()) != null)
                                                               res = (Integer)variables.get(i.getText());
                                                            else
                                                               res = 0;}

                    }
                    break;
                case 3 :
                    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:51:32: PARENTESIS_A e= expr PARENTESIS_C
                    {
                    match(input,PARENTESIS_A,FOLLOW_PARENTESIS_A_in_exp_base311); if (state.failed) return res;

                    pushFollow(FOLLOW_expr_in_exp_base315);
                    e=expr();

                    state._fsp--;
                    if (state.failed) return res;

                    match(input,PARENTESIS_C,FOLLOW_PARENTESIS_C_in_exp_base317); if (state.failed) return res;

                    if ( state.backtracking==0 ) {res = e;}

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return res;
    }
    // $ANTLR end "exp_base"



    // $ANTLR start "asignacion"
    // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:54:1: asignacion : var= IDENT ASIGNA a= expr PUNTO_COMA ;
    public final void asignacion() throws RecognitionException {
        Token var=null;
        int a =0;


        try {
            // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:54:11: (var= IDENT ASIGNA a= expr PUNTO_COMA )
            // C:\\Users\\usuario\\workspace\\Practica8-PL\\src\\main\\java\\practica8\\ExpresionesParser.g:54:13: var= IDENT ASIGNA a= expr PUNTO_COMA
            {
            var=(Token)match(input,IDENT,FOLLOW_IDENT_in_asignacion329); if (state.failed) return ;

            match(input,ASIGNA,FOLLOW_ASIGNA_in_asignacion331); if (state.failed) return ;

            pushFollow(FOLLOW_expr_in_asignacion335);
            a=expr();

            state._fsp--;
            if (state.failed) return ;

            match(input,PUNTO_COMA,FOLLOW_PUNTO_COMA_in_asignacion337); if (state.failed) return ;

            if ( state.backtracking==0 ) {variables.put(var.getText(), a); System.out.println("Asignacion("+var.getText()+"): "+a);}

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "asignacion"

    // Delegated rules


 

    public static final BitSet FOLLOW_instruccion_in_entrada58 = new BitSet(new long[]{0x0000000000006102L});
    public static final BitSet FOLLOW_asignacion_in_entrada60 = new BitSet(new long[]{0x0000000000006102L});
    public static final BitSet FOLLOW_expr_in_instruccion73 = new BitSet(new long[]{0x0000000000010000L});
    public static final BitSet FOLLOW_PUNTO_COMA_in_instruccion75 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_exp_mult_in_expr91 = new BitSet(new long[]{0x0000000000000C02L});
    public static final BitSet FOLLOW_MAS_in_expr97 = new BitSet(new long[]{0x0000000000006100L});
    public static final BitSet FOLLOW_exp_mult_in_expr101 = new BitSet(new long[]{0x0000000000000C02L});
    public static final BitSet FOLLOW_MENOS_in_expr107 = new BitSet(new long[]{0x0000000000006100L});
    public static final BitSet FOLLOW_exp_mult_in_expr111 = new BitSet(new long[]{0x0000000000000C02L});
    public static final BitSet FOLLOW_exp_base_in_exp_mult130 = new BitSet(new long[]{0x0000000000001082L});
    public static final BitSet FOLLOW_MULT_in_exp_mult136 = new BitSet(new long[]{0x0000000000006100L});
    public static final BitSet FOLLOW_exp_base_in_exp_mult140 = new BitSet(new long[]{0x0000000000001082L});
    public static final BitSet FOLLOW_DIV_in_exp_mult146 = new BitSet(new long[]{0x0000000000006100L});
    public static final BitSet FOLLOW_exp_base_in_exp_mult150 = new BitSet(new long[]{0x0000000000001082L});
    public static final BitSet FOLLOW_NUMERO_in_exp_base175 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_IDENT_in_exp_base244 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_PARENTESIS_A_in_exp_base311 = new BitSet(new long[]{0x0000000000006100L});
    public static final BitSet FOLLOW_expr_in_exp_base315 = new BitSet(new long[]{0x0000000000008000L});
    public static final BitSet FOLLOW_PARENTESIS_C_in_exp_base317 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_IDENT_in_asignacion329 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_ASIGNA_in_asignacion331 = new BitSet(new long[]{0x0000000000006100L});
    public static final BitSet FOLLOW_expr_in_asignacion335 = new BitSet(new long[]{0x0000000000010000L});
    public static final BitSet FOLLOW_PUNTO_COMA_in_asignacion337 = new BitSet(new long[]{0x0000000000000002L});

}